#    GMail-Notifier - A cooler looking gmail notifier for Ubuntu
#    Copyright (C) 2009 Uday K Verma
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

def get_refresh_val (val):
    ''' Calculate seconds value from a given refresh value ranging from 0 - 300 '''
    if val < 60:
        return val;
    elif val < 240:
        return int(((val - 60) / 3 + 1) * 60)
    else:
        return int((((val - 240) / 12) + 1) * 3600)
        
def format_duration (val):
    ''' Format a given duration, the specified duration is in seconds '''
    hours = val / 3600; val = val % 3600
    mins = val / 60 ; val = val % 60
    secs = val
    time = ""
    if hours:
        time = time + "%d hours " % hours
    if mins:
        time = time + "%d mins " % mins
    if secs:
        time = time + "%d seconds" % secs
        
    return time
    